<?php
/**
 * 命令行入口
 */
define('RUN_START', microtime(true));
$_ENV['APP_MODULENAME'] = false;

ini_set('display_errors', 1);
//error_reporting(E_ALL);

$_argvs = parseArgv($_SERVER['argv']);
defined('DEBUG_CROND') or define('DEBUG_CROND', $_argvs['debug'] ?? false);

if (PHP_SAPI !== 'cli') {
    header('WWW-Authenticate: Basic realm="Login:"');
    header('HTTP/1.0 401 Unauthorized');
    die ("Not Authorized\n");
}

require dirname(__DIR__) . '/vendor/autoload.php';
include dirname(__DIR__) . '/bootstrap.php';


function parseArgv($args) {
    $options = [];
    for ($i = 1; $i < count($args); $i++) {
        if (preg_match('/^--(\w+)(=(.*))?$/', $args[$i], $matches))
        {
            $name = $matches[1];
            $value = $matches[3] ?? true;
            $options[$name] = $value;
        }
    }

    return $options;
}
